package javaCode;

import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;


/**
 * Created by lxy_920912 on 27/04/2017.
 */
public class Baidu2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();

        List<Integer> list = new ArrayList<>();
        for(int i = 0 ;i < n;i++){
            list.add(in.nextInt());
        }
        int result = 0;
        int count = 1;
        for(int  i = n-count;i >= 0;i--){
            int min = list.get(i);
            int min_index = i;
            for(int j = i-1;j>=0;j--){
                if(min > list.get(j)){
                    min = list.get(j);
                    min_index = j;
                    result++;
                }
            }
            result++;
            list.remove(min_index);
            list.add(min);
            count++;
        }
        System.out.println(result);
    }
}
